<?php
namespace app\index\controller;


use app\index\logic\AdminLogic;
use app\model\User;
use think\facade\Request;

class Admin
{
    /*
     * 报表列表
     */
    public function login(){

        $reqParam = Request::post();
        if(!isset($reqParam['phone']) || empty($reqParam['phone'])) fail('请输入账号');
        $phone = trim($reqParam['phone']);

        if(!isset($reqParam['pwd']) || empty($reqParam['pwd'])) fail('请输入账号密码');
        $pwd = trim($reqParam['pwd']);

        success(AdminLogic::login($phone,$pwd));
    }

    /*
     * 报表 提交
     */
    public function signReport(){

        if(!position(User::SYS_ADMIN))  fail('暂无权限');
        $reqParam = Request::get();
        $where = [
            ['us_status','=',1],
            ['organization.status','=',1]
        ];
        if(isset($reqParam['orgid']) && !empty($reqParam['orgid'])){
            $where[] = ['orgid','=',intval($reqParam['orgid'])];
        }
        $time = time();
        if(isset($reqParam['startTime']) && !empty($reqParam['startTime'])){
            $time = $reqParam['startTime'];
        }
        $where[] = ['us_start_time','>=',strtotime(date('Y-m-d',$time))];
        $where[] = ['us_start_time','<=',strtotime(date('Y-m-d 23:59:59',$time))];
        success(AdminLogic::signReport($where));
    }
}
